#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: mytar_argu.sh
# Description: 
#   
# Edit History: 
#   2010-12-23    File created.
#========================================================================
USAGE="Usage: `basename $0` [-c|-t] [files|directories]"
if [ $# -lt 2 ] ; then
	echo "$USAGE" ;
	exit 1 ;
fi
case "$1" in
	-t) shift ; TARGS="-tvf" ;
		for i in "$@" ; do
			if [ -f "$i" ] ; then
				FILES=`tar $TARGS "$i" 2>/dev/null`
				if [ $? -eq 0 ] ; then
					echo ; echo "$i" ; echo "$FILES"
				else
					echo "ERROR: $i not a tar file."
				fi
			else
				echo "ERROR: $i not a file."
			fi
		done
		;;
	-c) shift ; TARGS="-cvf" ;
		tar $TARGS archive.tar "$@"
		;;
	*) echo "$USAGE"
		exit 0
		;;
esac
exit $?

#$ ./mytar.sh -c fruits
#$ ./mytar.sh -t fruits
